home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / Q7LLWX (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  5.7 KB  |  152 lines

  1. package com.sun.java.swing.plaf.basic;
  2.  
  3. import com.sun.java.swing.AbstractButton;
  4. import com.sun.java.swing.JButton;
  5. import com.sun.java.swing.JSplitPane;
  6. import com.sun.java.swing.UIManager;
  7. import java.awt.Component;
  8. import java.awt.Container;
  9. import java.awt.Cursor;
  10. import java.awt.Dimension;
  11. import java.awt.Graphics;
  12. import java.beans.PropertyChangeEvent;
  13. import java.beans.PropertyChangeListener;
  14. import java.io.Serializable;
  15. import java.util.EventObject;
  16.  
  17. public class BasicSplitPaneDivider extends Container implements PropertyChangeListener, Serializable {
  18.    protected static final int ONE_TOUCH_SIZE = 5;
  19.    protected static final int ONE_TOUCH_OFFSET = 2;
  20.    protected DragController dragger;
  21.    protected BasicSplitPaneUI splitPaneUI;
  22.    protected int dividerSize = 0;
  23.    protected Component hiddenDivider;
  24.    protected JSplitPane splitPane;
  25.    protected MouseHandler mouseHandler;
  26.    protected int orientation;
  27.    protected JButton leftButton;
  28.    protected JButton rightButton;
  29.    static final Cursor horizontalCursor = Cursor.getPredefinedCursor(11);
  30.    static final Cursor verticalCursor = Cursor.getPredefinedCursor(9);
  31.    static final Cursor defaultCursor = Cursor.getPredefinedCursor(0);
  32.  
  33.    public BasicSplitPaneDivider(BasicSplitPaneUI ui) {
  34.       ((Container)this).setLayout(new DividerLayout(this));
  35.       this.setBasicSplitPaneUI(ui);
  36.       this.orientation = this.splitPane.getOrientation();
  37.       ((Component)this).setBackground(UIManager.getColor("SplitPane.background"));
  38.    }
  39.  
  40.    protected JButton createLeftOneTouchButton() {
  41.       JButton b = new 1(this);
  42.       ((AbstractButton)b).setFocusPainted(false);
  43.       ((AbstractButton)b).setBorderPainted(false);
  44.       return b;
  45.    }
  46.  
  47.    protected JButton createRightOneTouchButton() {
  48.       JButton b = new 2(this);
  49.       ((AbstractButton)b).setFocusPainted(false);
  50.       ((AbstractButton)b).setBorderPainted(false);
  51.       return b;
  52.    }
  53.  
  54.    protected void dragDividerTo(int location) {
  55.       this.splitPaneUI.dragDividerTo(location);
  56.    }
  57.  
  58.    protected void finishDraggingTo(int location) {
  59.       this.splitPaneUI.finishDraggingTo(location);
  60.    }
  61.  
  62.    public BasicSplitPaneUI getBasicSplitPaneUI() {
  63.       return this.splitPaneUI;
  64.    }
  65.  
  66.    public int getDividerSize() {
  67.       return this.dividerSize;
  68.    }
  69.  
  70.    public Dimension getPreferredSize() {
  71.       return new Dimension(this.getDividerSize(), this.getDividerSize());
  72.    }
  73.  
  74.    protected void oneTouchExpandableChanged() {
  75.       if (this.splitPane.isOneTouchExpandable() && this.leftButton == null && this.rightButton == null) {
  76.          this.leftButton = this.createLeftOneTouchButton();
  77.          if (this.leftButton != null) {
  78.             this.leftButton.addActionListener(new LeftActionListener(this));
  79.          }
  80.  
  81.          this.rightButton = this.createRightOneTouchButton();
  82.          if (this.rightButton != null) {
  83.             this.rightButton.addActionListener(new RightActionListener(this));
  84.          }
  85.  
  86.          if (this.leftButton != null && this.rightButton != null) {
  87.             ((Container)this).add(this.leftButton);
  88.             ((Container)this).add(this.rightButton);
  89.          }
  90.       }
  91.  
  92.       ((Container)this).invalidate();
  93.       ((Container)this).validate();
  94.    }
  95.  
  96.    public void paint(Graphics g) {
  97.       super.paint(g);
  98.    }
  99.  
  100.    protected void prepareForDragging() {
  101.       this.splitPaneUI.startDragging();
  102.    }
  103.  
  104.    public void propertyChange(PropertyChangeEvent e) {
  105.       if (((EventObject)e).getSource() == this.splitPane) {
  106.          if (e.getPropertyName().equals("orientation")) {
  107.             this.orientation = this.splitPane.getOrientation();
  108.             ((Container)this).invalidate();
  109.             ((Container)this).validate();
  110.          } else if (e.getPropertyName().equals("oneTouchExpandable")) {
  111.             this.oneTouchExpandableChanged();
  112.          }
  113.       }
  114.  
  115.    }
  116.  
  117.    public void setBasicSplitPaneUI(BasicSplitPaneUI newUI) {
  118.       if (this.splitPane != null) {
  119.          this.splitPane.removePropertyChangeListener(this);
  120.          if (this.mouseHandler != null) {
  121.             this.splitPane.removeMouseListener(this.mouseHandler);
  122.             this.splitPane.removeMouseMotionListener(this.mouseHandler);
  123.             this.mouseHandler = null;
  124.          }
  125.       }
  126.  
  127.       this.splitPaneUI = newUI;
  128.       if (newUI != null) {
  129.          this.splitPane = newUI.getSplitPane();
  130.          if (this.splitPane != null) {
  131.             if (this.mouseHandler == null) {
  132.                this.mouseHandler = new MouseHandler(this);
  133.             }
  134.  
  135.             this.splitPane.addMouseListener(this.mouseHandler);
  136.             this.splitPane.addMouseMotionListener(this.mouseHandler);
  137.             this.splitPane.addPropertyChangeListener(this);
  138.             if (this.splitPane.isOneTouchExpandable()) {
  139.                this.oneTouchExpandableChanged();
  140.             }
  141.          }
  142.       } else {
  143.          this.splitPane = null;
  144.       }
  145.  
  146.    }
  147.  
  148.    public void setDividerSize(int newSize) {
  149.       this.dividerSize = newSize;
  150.    }
  151. }
  152.